<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <input type="text" class="username">
  <input type="password" class="password">
  <button>添加</button>
  <script>
    // 下列代码有什么错误？  有2出大错误哦
//  const username = document.querySelector('.username').value
//  const password = document.querySelector('.password').value
//  document.querySelector('button').addEventListener('click', function () {
//    const obj = {
//      username,
//      password,
//      sayHi = () {
//        console.log('hi~')
//      }
//    }
//    console.log(obj)
//  })

    
     document.querySelector('button').addEventListener('click', function () {
      const username = document.querySelector('.username').value
     const password = document.querySelector('.password').value
       const obj = {
         username,
         password,
         sayHi  () {
           console.log('hi~')
         }
       }
       console.log(obj)
     })
  </script>
</body>
</html>